import { API_URL, get, post, postWithProg } from "./base";

interface CreateReq {
    type_id: number,
    name: string,
    description: string,
    version: string,
    body: Uint8Array,
}

export async function createFirmFile(req: CreateReq, progress: (n: number) => void) {
    await postWithProg<CreateReq, number>('/firm_file/create', req, progress);
}

export interface TbFirmFile {
    id: number,
    name: string,
    description: string,
    version: string,
    size: number,
    create_timestamp: number
}

export async function queryFirmFile(type_id: number) {
    const resp = await get(`/firm_file/query?type_id=${type_id}`);
    return await resp.parse<TbFirmFile[]>();
}

export async function deleteFirmFile(id: number) {
    await post('/firm_file/delete', id);
}

export function downloadFirmFileUrl(id: number) {
    return `${API_URL}/firm_file/download?id=${id}`;
}




